package com.gopay.solution.dao.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.solution.dao.SsCapSolutionRelDAO;
import com.gopay.solution.domain.po.SsCapSolutionRel;

/**
 * 
 * @SsCapSolutionRelDAOImpl.java
 * @author liujy
 * @2013-8-2 下午5:15:17 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository(value = "ssCapSolutionRelDAO")
public class SsCapSolutionRelDAOImpl extends BaseDAOImpl<SsCapSolutionRel, Serializable> implements SsCapSolutionRelDAO {

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public SsCapSolutionRel getByCustIdAndPdAndSolType(String custId, String prodCode, String solType) {
        String hql = " from SsCapSolutionRel rel where rel.custId = :custId and " +
        		"rel.solutionType = :solutionType and rel.prodCode = :prodCode";

        Map param = new HashMap();
        param.put("prodCode", prodCode);
        param.put("custId", custId);
        param.put("solutionType", solType);

        List<SsCapSolutionRel> res = super.findByHql(hql, param);

        if (res != null && res.size() > 0) {
            if (res.size() == 1)
                return res.get(0);

            // (prodCode, solutionType) should be the Pk of this table,
            // Otherwise
            // throw Exception.
            throw new IllegalStateException("More than One Record Showed Up!, SsCapSolutionRel.prodCode =" + prodCode
                    + " , SsCapSolutionRel.solutionType = " + solType);
        }
        return null;
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public List<SsCapSolutionRel> getByCustIdAndSolType(String custId, String solType) {
        String hql = " from SsCapSolutionRel rel where rel.custId = :custId and " +
        		"rel.solutionType = :solutionType";

        Map param = new HashMap();
        param.put("custId", custId);
        param.put("solutionType", solType);

        List<SsCapSolutionRel> res = super.findByHql(hql, param);

        if (res != null && res.size() > 0) {
        	return res;
        }else{
        	return null;
        }
        
    }
}
